package com.southwind.springboottest.controller;

import com.southwind.springboottest.entity.Book;
import com.southwind.springboottest.repository.BookRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/book")
public class BookHandler {
     @Autowired
    private BookRepository bookRepository;

     @GetMapping("findAll/{page}/{size}")
     public Page<Book> findAll(@PathVariable("page")Integer page, @PathVariable("size")Integer size){
         Pageable pageable = PageRequest.of(page-1,size);
         return bookRepository.findAll(pageable);
     }
}
